package com.zjsd.sqeybusiness.utils;


import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Master
 *
 */
public class TelNoUtil
{
    private static final int MIN_TELNO_LEN = 3;

    //识别电话号码
    public static List<String> parseTelNo(String str)
    {
        List<String> telNo = new ArrayList<String>();
        String strNo = null;

        if(null == str || str.length() <= 0) {
            return telNo;
        }

        Pattern p = Pattern.compile("(\\(?\\d+\\)?\\-?)?\\d+(\\-?\\d+)*");
        Matcher m = p.matcher(str);
        while (m.find()) {
            strNo = m.group();
            if(strNo.length() >= MIN_TELNO_LEN) {
                telNo.add(m.group());
            }
        }

        return telNo;
    }
    //将识别出来的电话号码处理为一个只有数字的号码
    public static String parseTelNoToDail(String strTelNo)
    {
        StringBuffer sbrDailNo = new StringBuffer();

        Pattern p = Pattern.compile("\\d+");
        Matcher m = p.matcher(strTelNo);
        while (m.find()) {
            sbrDailNo.append(m.group());
        }

        return sbrDailNo.toString();
    }

    public static boolean isMobileNO(String mobiles) {
        Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }


    public static void main(String[] args) {
        String test = "接口洛杉矶的看法截单数量科技发大水18663563979时空来电解放1123路口见识到了考计算机弗兰克斯缴费的亏了多少12132123";
         List<String>  list = parseTelNo(test);
         for(String temp : list){
             if(isMobileNO(temp)){
                 temp =  temp.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
             }
             System.out.println("识别出的电话号码：" + temp);
         }
    }

}
